package a_doubleWrite;

/**
 * 暴力法
 * 例如对于 s = "( ) ) ( ( ) )"。
 *
 * @author: luolidong
 * @create: 2021-07-20 19:43
 * @version: 1.0
 */
public class L32_violence {
    public int longestValidParentheses(String s) {
        int i = 0;
        int max = 0;
        int count = 0;
        for (int j = 0; j < s.length(); j++) {
            i = j;
            while (i < s.length()) {
                if (i == s.length() - 1) max = Math.max(i - j + 1, max);
                if (s.charAt(j) == ')' && count == 0) {
                    max = Math.max(i - j + 1, max);
                    break;
                }
                if (s.charAt(j) == '(') {
                    count++;
                } else {
                    count--;
                }
                i++;
            }
        }
        return max;
    }
}
